Skip to content

helm: add db-init pre-install hook for external PostgreSQL#311

Closed
Soju06 wants to merge 2 commits intomainfrom
helm/db-init-hook
Closed

helm: add db-init pre-install hook for external PostgreSQL#311
Soju06 wants to merge 2 commits intomainfrom
helm/db-init-hook

Conversation

@Soju06
Copy link
Copy Markdown
Owner

@Soju06 Soju06 commented Apr 3, 2026

Summary

  • Add optional pre-install hook Job that creates databases and users on external PostgreSQL
  • Only runs when dbInit.enabled=true and postgresql.enabled=false (external DB mode)
  • Supports multiple databases via dbInit.databases list
  • Admin credentials via plain value or Secret reference

Motivation

When using external managed PostgreSQL (OCI, RDS, Cloud SQL), users must manually create application databases and users before deploying codex-lb. This hook automates that step.

Changes

  • templates/hooks/db-init-job.yaml: New pre-install hook Job
  • values.yaml: Add dbInit section

@Soju06
Copy link
Copy Markdown
Owner Author

Soju06 commented Apr 3, 2026

Consolidating into 2 PRs: chart features + docs

@Soju06 Soju06 closed this Apr 3, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f18d345f03

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +93 to +94
nodeSelector:
{{- . | nindent 8 }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Align deployment nodeSelector with pod-spec indentation

This nodeSelector key is indented one space deeper than sibling pod-spec fields, so when nodeSelector/global.nodeSelector is set and this block renders, Helm emits invalid YAML for the Deployment and install/template fails with a parse error. The key needs to align with other fields under spec.template.spec.

Useful? React with 👍 / 👎.

Comment on lines +39 to +41
{{- with (include "codex-lb.nodeSelector" .) }}
nodeSelector:
{{- . | nindent 8 }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Align migration hook nodeSelector indentation

The migration Job has the same over-indented nodeSelector block, which renders invalid YAML whenever a node selector is configured; because migration.enabled defaults to true, this can break installs/upgrades in common configurations that set node selectors. The nodeSelector key must be aligned with other fields under spec.template.spec.

Useful? React with 👍 / 👎.

{{- range .Values.dbInit.databases }}
DO $$ BEGIN
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '{{ .user }}') THEN
CREATE ROLE {{ .user }} WITH LOGIN PASSWORD '{{ .password }}';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Escape db-init SQL identifiers and literals

This statement injects Helm values directly into SQL without identifier/literal escaping, so valid inputs like a username containing - or a password containing ' will break the hook (and can alter SQL semantics). Use SQL-safe quoting (%I/%L, quote_ident, quote_literal) for role/database names and passwords before executing.

Useful? React with 👍 / 👎.

Comment on lines +17 to +19
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply merged nodeSelector helper in db-init hook

The new db-init Job reads only .Values.nodeSelector, so global.nodeSelector is ignored for this hook while other pods were switched to the merged helper. In clusters relying on global selectors for placement/network access, db-init can run on unintended nodes or fail scheduling; this hook should use the same merged selector logic as deployment/migration/test pods.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant